package com.acwing.partition4;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/1/23 8:57
 */
public class AC393雇佣收银员 {

    private static final int N = 25, M = 4 * N, INF = 0x3f3f3f3f;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    private static int[] dist = new int[N], cnt = new int[N];
    private static boolean[] inQueue = new boolean[N];

    private static int n = 0, idx = 0;
    private static int[] r = new int[N], nums = new int[N];

    private static Queue<Integer> queue = new ArrayDeque<>(N);

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = Integer.parseInt(reader.readLine());
        while (t-- > 0) {
            String[] s = reader.readLine().split("\\s+");
            for (int i = 1; i <= 24; i++) r[i] = Integer.parseInt(s[i - 1]);
            n = Integer.parseInt(reader.readLine());
            for (int i = 0; i < n; i++) nums[Integer.parseInt(reader.readLine()) + 1]++;
            int ans = binarySearch();
            if (ans == -1) writer.write("No Solution\n");
            else writer.write(ans + "\n");
        }
        writer.flush();
    }

    private static int binarySearch() {
        int left = 0, right = n;
        while (left < right) {
            int mid = (left + right) >> 1;
            if (!spfa(mid)) right = mid;
            else left = mid + 1;
        }
        if (!spfa(left)) return left;
        return -1;
    }

    private static boolean spfa(int s24) {
        initEdge(s24);
        queue.clear();
        dist[0] = 0;
        queue.add(0);
        inQueue[0] = true;
        while (!queue.isEmpty()) {
            int u = queue.poll();
            inQueue[u] = false;
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (dist[v] < dist[u] + weight[i]) {
                    dist[v] = dist[u] + weight[i];
                    cnt[v] = cnt[u] + 1;
                    if (cnt[v] >= 25) return true;
                    if (inQueue[v]) continue;
                    queue.add(v);
                    inQueue[v] = true;
                }
            }
        }
        return false;
    }

    private static void initEdge(int s24) {
        for (int i = 0; i < N; i++) {
            head[i] = -1;
            cnt[i] = 0;
            inQueue[i] = false;
            dist[i] = -INF;
        }
        idx = 0;
        createEdge(0, 24, s24);
        createEdge(24, 0, -s24);
        for (int i = 1; i <= 24; i++) createEdge(i, i - 1, -nums[i]);
        for (int i = 8; i <= 24; i++) createEdge(i - 8, i, r[i]);
        for (int i = 1; i <= 7; i++) createEdge(i + 16, i, -s24 + r[i]);
    }

    private static void createEdge(int u, int v, int w) {
        element[idx] = v;
        next[idx] = head[u];
        head[u] = idx;
        weight[idx++] = w;
    }
}
